/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing.jee.web.view;

import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
import com.vaadin.event.dd.acceptcriteria.ClientSideCriterion;
import com.vaadin.event.dd.acceptcriteria.Not;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.Window.Notification;
import java.util.Date;
import testing.jee.entity.User;
import testing.jee.entity.Workpackage;

/**
 *
 * @author kreisera
 */
public class AssignmentDropHandler implements DropHandler {

    final Date date;
    final User user;
    final AssignWorkpackageView view;
    AcceptCriterion acceptCriterion;

    public AssignmentDropHandler(Date date, User user, AssignWorkpackageView view) {
        this.date = date;
        this.user = user;
        this.view = view;
        acceptCriterion = AcceptAll.get();

    }

    @Override
    public void drop(DragAndDropEvent event) {
        Workpackage toAssign = (Workpackage) ((DragAndDropWrapper) event.getTransferable().getSourceComponent()).getData();
        view.req.assignWorkpackage(toAssign.getId(), user, date);
        view.update();
        view.getApplication().getMainWindow().showNotification("Workpackage successfully assigned!", Notification.TYPE_HUMANIZED_MESSAGE);
    }

    @Override
    public AcceptCriterion getAcceptCriterion() {
        return acceptCriterion;
    }
}
